package com.lw.sbdemo2.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>标题: 消息体工具方法</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2017</p>
 * <p>公司: 智业软件</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date: 2017/7/6
 */
public class MessageUtil {

    /**
     * 日志对象
     */
    private static final Logger logger = LoggerFactory.getLogger(MessageUtil.class);

    /**
     * 获取message节点值
     *
     * @param nodeCode 节点名称
     * @param message  xml源
     * @return
     */
    public static String getMessageProperty(String nodeCode, String message) {
        final Pattern nodePattern = Pattern.compile("<" + nodeCode + ">([\\s\\S]*?)</" + nodeCode + ">");
        final Matcher nodeMatcher = nodePattern.matcher(message);
        String nodeText = "";
        //获取匹配的第一个节点文本
        if (nodeMatcher.find()) {
            nodeText = nodeMatcher.group(1);
        }
        return nodeText;
    }
}
